//本程序演示线程的创建
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <pthread.h>
void* add(void* arg);
void* show(void* arg);
int num=0;
int main(int argc,char* argv[])
{
	pthread_t tid1=0;
	pthread_t tid2=0;
	int ret = pthread_create(&tid1, NULL, add, NULL);
	if(0!=ret)
	{
		printf("pthread_create failed");
		exit(-1);
	}
	ret = pthread_create(&tid2, NULL, show, NULL);
	if(0!=ret)
	{
		printf("pthread_create failed");
		exit(-1);
	}
	//等待线程退出
	sleep(1);
	printf("before join\n");
	pthread_join(tid1,NULL);
	pthread_join(tid2,NULL);
	printf("after jion\n");
	return 0;
}
void* add(void* arg)
{
	for(int i=0; i<5; ++i)
	{
		sleep(1);
		++num;
	}
	return nullptr;
}
void* show(void* arg)
{
	for(int i=0; i<5; ++i)
	{
		sleep(1);
		printf("num=%d\n",num);
	}
	return nullptr;
}

